from django.db import models

# Create your models here.
# 简单的学生管理系统

"""
学生

姓名、年龄、性别、学号、班级

班级

班级名称

课程

课程名称、授课教师

教师

姓名、年龄、性别、工号、职称
"""

# 班级
class ClassModel(models.Model):
    name = models.CharField(max_length=32, verbose_name='班级名称')
    def __str__(self):
        return self.name
    class Meta:
        verbose_name = '班级'
        verbose_name_plural = verbose_name

# 学生
# 一对一 一对多 多对多三种关系
class StudentsModel(models.Model):
    name = models.CharField(max_length=32, verbose_name='姓名')
    age = models.IntegerField(verbose_name='年龄')
    gender = models.CharField(max_length=6, verbose_name='性别')
    number = models.CharField(max_length=32, verbose_name='学号')
    class_id = models.ForeignKey(to='ClassModel', on_delete=models.SET_NULL, null=True, verbose_name='班级')
    def __str__(self):
        return self.name
    class Meta:
        verbose_name = '学生'
        verbose_name_plural = verbose_name
        ordering = ['number']

# 课程
class CourseModel(models.Model):
    name = models.CharField(max_length=32, verbose_name='课程名称')
    teacher = models.ForeignKey(to='TeacherModel', on_delete=models.SET_NULL, null=True, verbose_name='授课教师')
    def __str__(self):
        return self.name
    class Meta:
        verbose_name = '课程'
        verbose_name_plural = verbose_name


# 教师
class TeacherModel(models.Model):
    name = models.CharField(max_length=32, verbose_name='姓名')
    age = models.IntegerField(verbose_name='年龄')
    gender = models.CharField(max_length=6, verbose_name='性别')
    number = models.CharField(max_length=32, verbose_name='工号')
    title = models.CharField(max_length=32, verbose_name='职称')
    def __str__(self):
        return self.name
    class Meta:
        verbose_name = '教师'
        verbose_name_plural = verbose_name